﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StableDiffusionTools.Framework
{
    public class CountProgress
    {
        public int Total { get; private set; }
        public int Completed { get; private set; }
        public int Remaining { get => Total - Completed; }

        public CountProgress(int total, int completed)
        {
            Total = total;
            Completed = completed;
        }

        public int GetProgressInt()
        {
            return (int)GetProgressFloat();
        }

        public float GetProgressFloat()
        {
            return (float)Completed / Total * 100;
        }

        public TimeSpan GetEstimateTimeUntilCompleted(TimeSpan elapsed)
        {
            double msPerItem = elapsed.TotalMilliseconds / Completed;
            return TimeSpan.FromMilliseconds(msPerItem * Remaining);
        }

        public bool IsCompleted()
        {
            return Total == Completed;
        }

        public override string ToString()
        {
            return $"{Completed}/{Total} - {GetProgressFloat():0.00}%";
        }

        public string FormatExtendedStatus(TimeSpan elapsed)
        {
            return $"{Completed}/{Total} - {GetProgressFloat():0.0}% - Elapsed: {elapsed:hh\\:mm\\:ss} - ETA: {GetEstimateTimeUntilCompleted(elapsed):hh\\:mm\\:ss}";
        }
    }
}
